def Prosto(n):
    t = True
    for i in range (2, int(n**0.5)+1):
        if n % i == 0:
            t = False
    return t
s = input()
alf = ['zero','one','two','three','four','five','six','seven','eight','nine']
s = s.split()
p = 0
if(s[0] in alf) and (s[1] in alf) and (s[2] in alf):
    chislo = alf.index(s[0])*100+alf.index(s[1])*10+alf.index(s[2])
    if Prosto(chislo):
        p = chislo
    else:
        for i in range(chislo-1,2,-1):
            if Prosto(chislo):
                p = i
                break
        for i in range(chislo+1,1500):
            if Prosto(i)and(chislo-p)>(i-chislo):
                p = i
                break
    print(p)
else:
    print('Wrong input')
